//
//  HWPersonalInformationViewController.m
//  HWPromoteProjectAPP
//
//  Created by 陈道斌 on 2020/3/10.
//  Copyright © 2020 陈道斌. All rights reserved.
//

#import "HWPersonalInformationViewController.h"
#import "HWPersonalInformationCell.h"
#import "HWPersonalInformationModel.h"
#import "HWShuRuTankuanView.h"

@interface HWPersonalInformationViewController ()<UITableViewDelegate,UITableViewDataSource,HWShuRuTankuanViewDelegate>
@property(strong,nonatomic) UITableView *mainTabelView;

@property(strong,nonatomic) UIView *hederView;
@property(strong,nonatomic) UIImageView *headImageView;
@property(strong,nonatomic) UILabel *nameLabel; // 名称

@property(strong,nonatomic) NSDictionary *shujuDic;
@property(strong,nonatomic) NSMutableArray *dataMuArr;
@property(strong,nonatomic) NSArray *leftArr;




@end

@implementation HWPersonalInformationViewController


- (UITableView *)mainTabelView {
    
    if (_mainTabelView == nil) {
        _mainTabelView = [[UITableView alloc]initWithFrame:CGRectMake(0,0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
        _mainTabelView.delegate = self;
        _mainTabelView.dataSource = self;
        _mainTabelView.backgroundColor =beijingyanSe;
        _mainTabelView.separatorStyle =  UITableViewCellSeparatorStyleNone;
        

    }

    return _mainTabelView;
    
    
    
    
    
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBarHidden = NO;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setupUI];
    
    // 添加
    [self addheaderView];
    
    [self sendNetworkRequest];
    
    
    
}

- (void)setupUI {
    
    self.navigationItem.title = @"个人信息";
    self.view.backgroundColor = beijingyanSe;
    self.leftArr = @[@"昵称",@"ID",@"QQ",@"手机",@"邮箱",@"支付宝账号",@"收款人",@"联系地址"];
    
    [self.view addSubview:self.mainTabelView];
    

    
}


- (void)addheaderView {
    
    self.hederView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 104)];
    self.hederView.backgroundColor = [UIColor whiteColor];
    self.mainTabelView.tableHeaderView = self.hederView;
    // [UIDevice UIUserInterfaceStyle];
  //   [[UIDevice currentDevice] UIUserInterfaceStyle];
    
    
//    if (@available(iOS 13.0, *)){
//        
//        if(self.overrideUserInterfaceStyle == UIUserInterfaceStyleLight){
//            
//            
//            
//            
//            
//        } else {
//            
//            
//            
//        }
//        
//    }
    
        UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(20, 20,100 ,84)];
        
        label.font = [UIFont systemFontOfSize:14.0];
        label.textColor = RGB(68, 68, 68);
        label.backgroundColor = [UIColor whiteColor];
           //        label.textAlignment = UITextAlignmentLeft;
        label.text = @"头像";
        [self.hederView  addSubview:label];
    
    
        UIImageView *iamgeView = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-64-20, 20, 64, 64)];
        iamgeView.backgroundColor = [UIColor redColor];
        iamgeView.layer.cornerRadius = 12;
        iamgeView.layer.masksToBounds = YES;
       self.headImageView = iamgeView;
        [self.hederView addSubview:iamgeView];
    
    
       UIView *fengeview = [[UIView alloc]initWithFrame:CGRectMake(0, 103, SCREEN_WIDTH, 1)];
       fengeview.backgroundColor = RGB(245, 245, 245);
       [self.hederView addSubview:fengeview];
    
    
      UIView *footerView =[[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 56)];
      footerView.backgroundColor = beijingyanSe;
      self.mainTabelView.tableFooterView  = footerView;
    
    
           UILabel *footlabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10,SCREEN_WIDTH-40 ,36)];
           
           footlabel.font = [UIFont systemFontOfSize:14.0];
           footlabel.textColor = RGB(255, 182, 10);
          footlabel.backgroundColor = RGB(255, 250, 238);
              //        label.textAlignment = UITextAlignmentLeft;
           footlabel.text = @"注意：信息添加后禁止修改";
           [self.hederView  addSubview:label];
    
    
       
    
    
    

}



// 发送网络请求
- (void)sendNetworkRequest {
    
    
    
     
         NSString *tStr = [NSString stringWithFormat:@"%ld",[WMUtil getTimeSp]];
         NSString *uid =  [HWLocallyStoredData getLoginUserID];
         NSString *signStr = [NSString stringWithFormat:@"%@%@%@",uid,tStr,@"adesxloksy13s98adv"];
         NSString  *signStrMd5  =   [WMUtil md5HexDigest:signStr];
           
        
        
        
          NSDictionary *parametes = @{      @"ios" : @"1",
                                       @"ct" : @"app",
                                        @"ac" : @"my_config",
                                        @"t" : tStr,
                                        @"uid":uid,
                                        @"sign" :signStrMd5
                                        };
        
        
            [HWWebUtils doGetWithParameters:parametes progress:nil success:^(id response) {
                  
                 

                  NSString *codeStr =  [NSString stringWithFormat:@"%@",response[@"code"]];
                  if ([codeStr intValue] == 1) {
                 
                         NSLog(@"%@",response);
                      NSString *head = [NSString stringWithFormat:@"%@",response[@"data"][@"head"]];
                      [self.headImageView sd_setImageWithURL:[NSURL URLWithString:head] placeholderImage:nil];
                      self.nameLabel.text =  [NSString stringWithFormat:@"%@",response[@"data"][@"username"]];
                      
                      self.shujuDic = response[@"data"];
                      
                      [self shujuhuanjing];
                      
             
                
                      
                      [self.mainTabelView reloadData];
                      
                      
                      
                       
                  } else {
                      
                    [MBProgressHUD showError:response[@"message"]];
                                    
                
                      
                  }
                  
             
                  
              } failure:^(NSString *error) {
                 // [SVProgressHUD dismiss];
                  
                   [MBProgressHUD showSuccess:@"登录失败"];
                  [MBProgressHUD hideHUD];
                  
                  
              }];
        
    
    
    
    
    
    
    
}

- (void)shujuhuanjing {
    
    
     self.dataMuArr = [[NSMutableArray alloc]init];
    
      HWPersonalInformationModel *model1 = [[HWPersonalInformationModel alloc]init];
      model1.mingcheng =  self.shujuDic[@"username"];
    
      HWPersonalInformationModel *model2 = [[HWPersonalInformationModel alloc]init];
      model2.mingcheng =   [HWLocallyStoredData getLoginUserID];
    
    
    
    
     HWPersonalInformationModel *model3 = [[HWPersonalInformationModel alloc]init];
      model3.mingcheng =  self.shujuDic[@"qq"];
    
    
     HWPersonalInformationModel *model4 = [[HWPersonalInformationModel alloc]init];
     model4.mingcheng =  self.shujuDic[@"phone"];
    
    HWPersonalInformationModel *model5 = [[HWPersonalInformationModel alloc]init];
    model5.mingcheng =  self.shujuDic[@"email"];
    
    
    HWPersonalInformationModel *model6 = [[HWPersonalInformationModel alloc]init];
    model6.mingcheng =  self.shujuDic[@"bank_id"];
    
    
    HWPersonalInformationModel *model7 = [[HWPersonalInformationModel alloc]init];
    model7.mingcheng =  self.shujuDic[@"bank_user"];
    
    
    HWPersonalInformationModel *model8 = [[HWPersonalInformationModel alloc]init];
    model8.mingcheng =  self.shujuDic[@"address"];
    
     [self.dataMuArr addObject:model1];
      [self.dataMuArr addObject:model2];
      [self.dataMuArr addObject:model3];
      [self.dataMuArr addObject:model4];
      [self.dataMuArr addObject:model5];
      [self.dataMuArr addObject:model6];
      [self.dataMuArr addObject:model7];
      [self.dataMuArr addObject:model8];
   
    
    
    

      //  self.shujuDic
    
}



// 设置
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return 8;
    
    
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    static NSString *cellID = @"cellID";
    
    HWPersonalInformationCell  *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    

    if (!cell) {
        cell =  [[NSBundle mainBundle]loadNibNamed:@"HWPersonalInformationCell" owner:nil options:nil].firstObject;
    }
    
    NSString *leftStr = self.leftArr[indexPath.row];
    cell.mingchengLabel.text = [NSString stringWithFormat:@"%@",leftStr];

    HWPersonalInformationModel *model = self.dataMuArr[indexPath.row];
    
    if ([model.mingcheng isEqualToString:@""] || model.mingcheng  == nil) {
        cell.nichengLabel.text = @"未填写";
      
        
    } else {
    
        cell.nichengLabel.text = [NSString stringWithFormat:@"%@",model.mingcheng];
        
    }
     
    
    return  cell;
    
    
    
    
    
    
    
    
}



- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
     return  44*kHeightScale;
    
    
    
    
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (!(self.dataMuArr.count > 0)) {
        
        NSLog(@"jcjjjjjj");
        return;
        
    }
    
    
     HWPersonalInformationModel *model = self.dataMuArr[indexPath.row];
    
    if ([model.mingcheng isEqualToString:@""] || model.mingcheng  == nil) {

        HWShuRuTankuanView *fenxuan = [[HWShuRuTankuanView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kScreenH)];
        fenxuan.miashuLabel.text = [NSString stringWithFormat:@"%@",self.leftArr[indexPath.row]];
        fenxuan.miaoshutexefeild.placeholder = [NSString stringWithFormat:@"请输入%@",self.leftArr[indexPath.row]];
        fenxuan.delegate = self;
        fenxuan.indepath = indexPath;
        [kKeyWindow addSubview:fenxuan];
 



     } else {




    }
    
  
    
    
    
    
    
    
    
    
    
    
    

     
    
    
    
    
}



- (void)shuxingshuju {
    
    [self sendNetworkRequest];
    
    
}


@end
